package org.ushio.speech_module.notification;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.ushio.common_module.debounce.Debounce;
import org.ushio.common_module.util.response.ResponseResult;

import java.util.List;

/**
 * @author Asus
 */
@RestController
@RequestMapping("/api/notifications")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;

    /**
     * 创建通知
     * @param message
     * @return ResponseResult
     */
    @PostMapping
    @Debounce(interval = 500)
    public ResponseResult<Void> createNotification(@RequestBody String message) {
        notificationService.createNotification(message);
        return ResponseResult.success();
    }

    /**
     * 查询所有通知
     * @return ResponseResult
     */
    @GetMapping
    public ResponseResult<List<Notification>> getAllNotifications() {
        return ResponseResult.success(notificationService.getAllNotifications());
    }

    /**
     * 查询未读通知
     * @return ResponseResult
     */
    @GetMapping("/unread")
    public ResponseResult<List<Notification>> getUnreadNotifications() {
        return ResponseResult.success(notificationService.getUnreadNotifications());
    }

    /**
     * 查询已读通知
     * @return ResponseResult
     */
    @Debounce(interval = 500)
    @PutMapping("/{id}/read")
    public ResponseResult<Void> markNotificationAsRead(@PathVariable Long id) {
        notificationService.markNotificationAsRead(id);
        return ResponseResult.success();
    }
}
